package com.ryskoo.framework.core.utils;

import com.ryskoo.framework.core.bean.SimpleDataParam;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class CommonUtil {

	/**
	 * 将map<String,object>转换成list<SimpleDataParam>
	 * 主要用于前台 select 遍历显示 option
	 * boolean hasInitOption ： 是否添加初始化选项  --请选择--
	 */
	public static List<SimpleDataParam> converseSimpleDataParamMap(Map<String,?> map,boolean hasInitOption){
		List<SimpleDataParam> paramList = new ArrayList<SimpleDataParam>();
		SimpleDataParam param = null;
		if(hasInitOption){
			param = new SimpleDataParam();
			param.setKey("");
			param.setValue("--请选择--");
			paramList.add(param);
		}
		for (String key : map.keySet()) {
			Object value = map.get(key);
			param = new SimpleDataParam();
			param.setKey(key);
			param.setValue(value);
			paramList.add(param);
		}
		return paramList;
	}
}
